package com.zxh.blog.web.excel;

import java.text.SimpleDateFormat;
import java.util.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zxh.blog.util.excel.AffairsLotDTO;
import com.zxh.blog.util.excel.ExcelWriter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("excel")
public class ExcelController{

	@RequestMapping(value = "/download",method = RequestMethod.GET)
	public void getSystemExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String fileName = "attachment" + "_" + new SimpleDateFormat("yyyyMMdd").format(new Date())+".xlsx";
		response.reset();
		response.setHeader("Content-disposition", "attachment; filename="+ fileName);
		response.setContentType("application/vnd.ms-excel;charset=utf-8");
		response.setCharacterEncoding("utf-8");

		ServletOutputStream out = response.getOutputStream();
		ArrayList<AffairsLotDTO> list = new ArrayList<>();
		AffairsLotDTO affairsLotDTO = new AffairsLotDTO();
		affairsLotDTO.setProvince("777");
		affairsLotDTO.setCity("666");
		affairsLotDTO.setAddress("555");
		list.add(affairsLotDTO);
		ExcelWriter.exportExcel(list,out,AffairsLotDTO.class);
	}
}